package com.sunseagear.common.base.mvc.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 树抽象实体基类
 */
@Getter
public abstract class TreeEntity<T> extends DataEntity<T> {

    @TableField(value = "parent_id")
    protected T parentId; // 父编号

    @TableField(exist = false)
    List<TreeEntity> children = new ArrayList<>();


    public boolean isRoot() {
        return getParentId() == null || "0".equals(getParentId()) || "".equals(getParentId());
    }

    public Boolean isLeaf() {
        if (!this.children.isEmpty()) {
            return Boolean.FALSE;
        }

        return Boolean.TRUE;
    }

    public String getSeparator() {
        return "/";
    }


    public void setParentId(T parentId) {
        this.parentId = parentId;
    }

    public void setChildren(List<TreeEntity> children) {
        this.children = children;
    }

}
